# Maintainer (ArchLinux): Vesa Kaihlavirta <vegai@iki.fi>
# Maintainer (ArchLinux): Jaroslav Lichtblau <dragonlord@aur.archlinux.org>
# Maintainer (MSYS2): Ray Donnelly <mingw.android@gmail.com>
# Contributor (MSYS2): David Macek <david.macek.0@gmail.com>

_realname=quassel
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.14.0
pkgrel=1
pkgdesc="Next-generation distributed IRC client (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://quassel-irc.org/"
license=('GPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-qt5-tools")
depends=("${MINGW_PACKAGE_PREFIX}-qca-qt5"
        "${MINGW_PACKAGE_PREFIX}-qt5-base"
        "${MINGW_PACKAGE_PREFIX}-qt5-multimedia"
        "${MINGW_PACKAGE_PREFIX}-qt5-script"
        "${MINGW_PACKAGE_PREFIX}-boost"
         #"${MINGW_PACKAGE_PREFIX}-extra-cmake-modules" #TODO: only needed with WITH_KDE=ON
         "${MINGW_PACKAGE_PREFIX}-Snorenotify"
         "${MINGW_PACKAGE_PREFIX}-sonnet-qt5")
source=(https://quassel-irc.org/pub/${_realname}-${pkgver}.tar.bz2
        "0001-MinGW-w64-Adopt-FHS-Layout.patch")
sha256sums=('bbd46ca429c1518480904c9e2b0ab3a0412fe197f3ce4879974e06ed3a0093a3'
            '12b82e72c2d3a42872104906bad73f48c9b944506d086c0bcd710af904c9fcd8')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/0001-MinGW-w64-Adopt-FHS-Layout.patch
}

build() {
  cd "${srcdir}"
  [[ -d build-${CARCH} ]] && rm -rf build-${CARCH}
  mkdir build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  # ENABLE_SHARED=OFF is required or we get
  # "Trying to access a singleton that has not been instantiated yet"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DUSE_QT5=ON \
    -DWITH_KDE=OFF \
    -DCMAKE_BUILD_TYPE="Release" \
    -DWANT_CORE=ON \
    -DWANT_QTCLIENT=ON \
    -DWANT_MONO=ON \
    -DENABLE_SHARED=OFF \
    -Wno-dev \
    ../${_realname}-${pkgver}

  "${MINGW_PREFIX}"/bin/cmake.exe --build .
}

package() {
  cd "${srcdir}"/build-${CARCH}

  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install .
}
